package com.czy.owner.ui.bottom;


import android.content.Intent;
import android.graphics.Color;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.adapter.HomeHotShopBottomAdapter;
import com.czy.owner.adapter.HomeHotShopTopAdapter;
import com.czy.owner.adapter.HomeSecKillAdapter;
import com.czy.owner.adapter.ShoppingLikeAapter;
import com.czy.owner.adapter.ShoppingRecommendBrandAdapter;
import com.czy.owner.adapter.ShoppingSpecialAdapter;
import com.czy.owner.adapter.ShoppingStrategyAdapter;
import com.czy.owner.adapter.SpecialAreaAdapter;
import com.czy.owner.api.GuessYouLikeApi;
import com.czy.owner.api.ShoppingApi;
import com.czy.owner.callback.RecycleViewDivider;
import com.czy.owner.db.UserHelper;
import com.czy.owner.entity.CarInfo;
import com.czy.owner.entity.GuessYouLikeModel;
import com.czy.owner.entity.SessionInfoModel;
import com.czy.owner.entity.ShoppingModel;
import com.czy.owner.entity.SpecialModel;
import com.czy.owner.entity.WebViewRequestParam;
import com.czy.owner.global.Constants;
import com.czy.owner.net.http.HttpManager;
import com.czy.owner.net.listener.HttpOnNextListener;
import com.czy.owner.net.utils.JsonUtil;
import com.czy.owner.rxbus.RxBus;
import com.czy.owner.rxbus.Subscribe;
import com.czy.owner.rxbus.ThreadMode;
import com.czy.owner.rxbus.event.CommonEvent;
import com.czy.owner.ui.BaseFragment;
import com.czy.owner.ui.LuckDrawWebviewActivity;
import com.czy.owner.ui.MainActivity;
import com.czy.owner.ui.NewWebViewActivity;
import com.czy.owner.ui.WebViewActivity;
import com.czy.owner.ui.archive.CarDossierActivity;
import com.czy.owner.ui.archive.MaintenanceDetectionActivity;
import com.czy.owner.ui.archive.SelectIllegalQueryActivity;
import com.czy.owner.ui.coupons.CouponsActivity;
import com.czy.owner.ui.coupons.GetCouponsCenterActivity;
import com.czy.owner.ui.garage.PickBrandActivity;
import com.czy.owner.ui.headline.HeadLineActivity;
import com.czy.owner.ui.hotshop.GoodsDetailActivity;
import com.czy.owner.ui.hotshop.GoodsListActivity;
import com.czy.owner.ui.hotshop.GoodsSearchHistoryActivity;
import com.czy.owner.ui.hotshop.HotShopClassifyActivity2;
import com.czy.owner.ui.hotshop.HotShopWebActivity;
import com.czy.owner.ui.information.InformationDetailActivity;
import com.czy.owner.ui.seckill.SecKillActivity;
import com.czy.owner.ui.wheel.WheelListActivity;
import com.czy.owner.utils.GsonUtils;
import com.czy.owner.utils.MyLog;
import com.czy.owner.utils.PhoneUtils;
import com.czy.owner.utils.glide.GlideUtils;
import com.czy.owner.widget.CountdownView;
import com.czy.owner.widget.ImageCycleView;
import com.czy.owner.widget.NoScrollRecyclerView;
import com.czy.owner.widget.SeckillGridItemDecoration;
import com.czy.owner.widget.guidehelp.GuideHelper;
import com.easyrecycleview.EasyRecyclerView;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;
import com.easyrecycleview.decoration.DividerGridItemDecoration;
import com.easyrecycleview.decoration.DividerGridItemDecoration2;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

import static com.czy.owner.entity.WebViewRequestParam.REQUEST_GET;
import static com.czy.owner.entity.WebViewRequestParam.REQUEST_POST;

/**
 * Created by asus on 2017/12/18.
 * 新版首页
 */

public class ShoppingFragment2 extends BaseFragment implements RecyclerArrayAdapter.OnLoadMoreListener {


    @BindView(R.id.ll_shopping_search)
    LinearLayout llShoppingSearch;
    @BindView(R.id.easy_recycleview_like)
    EasyRecyclerView recycleViewLike;
    private int page = 1;
    private ShoppingLikeAapter shoppingLikeAapter;
    private Handler handler = new Handler();
    private int scrollY = 0;
    //跳转TYPE
    private static final int PLATFORM_TYPE = 0;
    private static int CLASSIFY_TYPE = 0;
    private static final int SEC_KILL_TYPE = 1;

    //秒杀
    private CountdownView cvSeckill;
    private LinearLayout llSecKill;
    private TextView tvSecKill;
    private TextView tvSecSign;
    private RecyclerView rvHomeSeckill;
    private boolean isStart = true;
    private long endTime = 0;

    //袋鼠头条
    private LinearLayout llDsHeadlLine;
    private TextView tvDsHeadLine;
    private boolean showFlagHeadLines = true;
    //活动区
    private ImageView ivFerrisWheel;
    private TextView tvFerrisWheel;
    private ImageView ivPriceRatio;
    private TextView tvPriceRatio;
    private TextView tvPriceRatioSub;
    //热门推荐
    private RecyclerView rvHomeHotTop;
    private RecyclerView rvHomeHotBottom;

    //新人大礼包
    private ImageView ivNewbornZone;
    //明星品牌
    private RecyclerView rvRecommendBrand;
    private LinearLayout llRecommendBrand;
    private ShoppingRecommendBrandAdapter shoppingRecommendBrandAdapter;
    //专题攻略
    private LinearLayout llStrategy;
    private RecyclerView recycleviewStrategy;
    private ShoppingStrategyAdapter shoppingStrategyAapter;

    //王洋的
    private final static int REQUEST_CODE_ADD_CAR = 1;
    private boolean needRefreshCar = false;

    //猜你喜欢头部
    private LinearLayout llGuessLike;
    private boolean isEverRequest = false;
    //banner与车辆
    private ImageCycleView icvShoppingBanner;
    private TextView tvAddCar;
    private TextView tvAddCarTips;
    private ImageView ivAddCar;

    //模板
    private RecyclerView rvShoppingSpecial;
    private NoScrollRecyclerView nrvSpecialArea;
    private SpecialAreaAdapter specialAreaAdapter;


    private ArrayList<String> mImageUrl = new ArrayList<>();//banner切换list
    private List<ShoppingModel.BannersBean> bannersList = new ArrayList<>();

    private boolean mIsRefreshing = false;

    @Override
    protected int attachLayoutRes() {
        return R.layout.fragment_shopping2;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {

        recycleViewLike.setAdapter(shoppingLikeAapter = new ShoppingLikeAapter(getActivity()));
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 2);
        gridLayoutManager.setSpanSizeLookup(shoppingLikeAapter.obtainGridSpanSizeLookUp(2));
        recycleViewLike.setLayoutManager(gridLayoutManager);
        recycleViewLike.addItemDecoration(new DividerGridItemDecoration2(getActivity(), 6f, R.drawable.shape_recyclerview_divider_decoration_commen));
        shoppingLikeAapter.setMore(R.layout.view_more, this);
        shoppingLikeAapter.addHeader(new RecyclerArrayAdapter.ItemView() {
            @Override
            public View onCreateView(ViewGroup parent) {
                LayoutInflater inflater = LayoutInflater.from(getActivity());
                View view = inflater.inflate(R.layout.header_fragment_shopping, null, false);

                //banner相关
                icvShoppingBanner = (ImageCycleView) view.findViewById(R.id.icv_shopping_banner);
                icvShoppingBanner.setRlBannerVisiable(View.INVISIBLE);


                //首页车辆相关

                view.findViewById(R.id.ll_add_car).setOnClickListener(onClick);
                ivAddCar = (ImageView) view.findViewById(R.id.iv_add_car);
                tvAddCar = (TextView) view.findViewById(R.id.tv_add_car);
                tvAddCarTips = (TextView) view.findViewById(R.id.tv_add_car_tips);


                //四个分类
                view.findViewById(R.id.ll_home_reach).setOnClickListener(onClick);
                view.findViewById(R.id.ll_home_vehicle).setOnClickListener(onClick);
                view.findViewById(R.id.ll_home_coupons).setOnClickListener(onClick);
                view.findViewById(R.id.ll_home_maintain).setOnClickListener(onClick);


                //FM908相关
                view.findViewById(R.id.ll_908).setOnClickListener(onClick);
                //安徽商报
                view.findViewById(R.id.ll_anhui).setOnClickListener(onClick);


                //新人大礼包相关
                ivNewbornZone = (ImageView) view.findViewById(R.id.iv_newborn_zone);
                ivNewbornZone.setOnClickListener(onClick);

                //活动区
                ivFerrisWheel = (ImageView) view.findViewById(R.id.iv_ferris_wheel);
                tvFerrisWheel = (TextView) view.findViewById(R.id.tv_ferris_wheel);
                ivPriceRatio = (ImageView) view.findViewById(R.id.iv_price_ratio);
                tvPriceRatio = (TextView) view.findViewById(R.id.tv_price_ratio);
                tvPriceRatioSub = (TextView) view.findViewById(R.id.tv_price_ratio_sub);
                view.findViewById(R.id.iv_shopping_experience).setOnClickListener(onClick);
                view.findViewById(R.id.iv_sign_in).setOnClickListener(onClick);

                //秒杀相关
                llSecKill = (LinearLayout) view.findViewById(R.id.ll_sec_kill);
                tvSecKill = (TextView) view.findViewById(R.id.tv_sec_kill);
                tvSecSign = (TextView) view.findViewById(R.id.tv_sec_sign);
                cvSeckill = (CountdownView) view.findViewById(R.id.cv_seckill);
                rvHomeSeckill = (RecyclerView) view.findViewById(R.id.rv_home_seckill);
                rvHomeSeckill.addItemDecoration(new SeckillGridItemDecoration(getActivity()));
                rvHomeSeckill.setItemAnimator(new DefaultItemAnimator());

                nrvSpecialArea = (NoScrollRecyclerView) view.findViewById(R.id.nrv_special_area);
                nrvSpecialArea.setLayoutManager(new LinearLayoutManager(mContext));
                nrvSpecialArea.addItemDecoration(new RecycleViewDivider(mContext, LinearLayoutManager.VERTICAL, R.drawable.shape_gray_divider_decoration));
                nrvSpecialArea.setAdapter(specialAreaAdapter = new SpecialAreaAdapter(mContext));
                specialAreaAdapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position, Object o) {

                        Intent intentSpecial = new Intent(getActivity(), WheelListActivity.class);
                        intentSpecial.putExtra("special_mode_id", specialAreaAdapter.getAllData().get(position).getSpecialModelId());
                        intentSpecial.putExtra("special_mode_name", specialAreaAdapter.getAllData().get(position).getSpecialModelName());
                        intentSpecial.putExtra("mFromTypeId",  specialAreaAdapter.getAllData().get(position).getSpecialModelId()+"");
                        startActivity(intentSpecial);

                    }
                });

                //袋鼠头条相关
                llDsHeadlLine = (LinearLayout) view.findViewById(R.id.ll_ds_head_line);
                llDsHeadlLine.setOnClickListener(onClick);
                tvDsHeadLine = (TextView) view.findViewById(R.id.tv_ds_head_line);

                //热门推荐
                rvHomeHotTop = (RecyclerView) view.findViewById(R.id.rv_shopping_recommend_top);
                rvHomeHotBottom = (RecyclerView) view.findViewById(R.id.rv_shopping_recommend_bottom);
                view.findViewById(R.id.tv_hot_recommend_more).setOnClickListener(onClick);
                rvHomeHotTop.addItemDecoration(new DividerGridItemDecoration(getActivity()));
                rvHomeHotBottom.addItemDecoration(new DividerGridItemDecoration(getActivity()));
                rvHomeHotBottom.setItemAnimator(new DefaultItemAnimator());
                rvHomeHotTop.setItemAnimator(new DefaultItemAnimator());

                //明星品牌

                llRecommendBrand = (LinearLayout) view.findViewById(R.id.ll_recommend_brand);
                rvRecommendBrand = (RecyclerView) view.findViewById(R.id.rv_recommend_brand);
                rvRecommendBrand.setLayoutManager(new GridLayoutManager(getActivity(), 3));
               // rvRecommendBrand.setItemAnimator(new DefaultItemAnimator());
                //   rvRecommendBrand.addItemDecoration();

                //专题模板
                rvShoppingSpecial = (RecyclerView) view.findViewById(R.id.rv_shopping_special);


                //专题攻略
                recycleviewStrategy = (RecyclerView) view.findViewById(R.id.rv_strategy);
                llStrategy = (LinearLayout) view.findViewById(R.id.ll_strategy);
                recycleviewStrategy.setLayoutManager(new LinearLayoutManager(getActivity()));
                recycleviewStrategy.setItemAnimator(new DefaultItemAnimator());
                //猜你喜欢
                llGuessLike = (LinearLayout) view.findViewById(R.id.ll_guess_like);


                return view;
            }

            @Override
            public void onBindView(View headerView) {

            }
        });

        recycleViewLike.addOnScrollListener(new RecyclerView.OnScrollListener() {
                                                @Override
                                                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                                                    super.onScrolled(recyclerView, dx, dy);
                                                    scrollY += dy;
                                                    if (scrollY < 40) {
                                                        llShoppingSearch.setBackgroundColor(Color.argb(0x00, 0x09, 0xc0, 0xc7));
                                                    } else {
                                                        int alpha = scrollY;
                                                        llShoppingSearch.setBackgroundColor(Color.argb((alpha <= 255 ? alpha : 255), 0x09, 0xc0, 0xc7));
                                                    }
                                                }

                                                @Override
                                                public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                                                    super.onScrollStateChanged(recyclerView, newState);
                                                }
                                            }

        );
        shoppingLikeAapter.setNoMore(R.layout.view_nomore, new RecyclerArrayAdapter.OnNoMoreListener() {
            @Override
            public void onNoMoreShow() {
            }

            @Override
            public void onNoMoreClick() {
                shoppingLikeAapter.resumeMore();
            }
        });

        shoppingLikeAapter.setError(R.layout.view_error_net, new RecyclerArrayAdapter.OnErrorListener() {
            @Override
            public void onErrorShow() {
                shoppingLikeAapter.resumeMore();

            }

            @Override
            public void onErrorClick() {
                shoppingLikeAapter.resumeMore();

            }
        });
        shoppingLikeAapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener<GuessYouLikeModel.ListBean>() {
            @Override
            public void onItemClick(View view, int position, GuessYouLikeModel.ListBean data) {
                Intent intent = new Intent(getActivity(), GoodsDetailActivity.class);
                intent.putExtra("goodsId", data.getGoodsId());
                intent.putExtra("mFromType",Constants.GOODSSOURCE_OTHER);
                intent.putExtra("mFromTypeId", "0");
                startActivity(intent);
            }
        });
        recycleViewLike.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                    getServerTime(0, 0, false);
                }
            }
        });
        if (!recycleViewLike.getSwipeToRefresh().isRefreshing()) {
            recycleViewLike.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    recycleViewLike.postDelayed(new Runnable() {
                        @Override
                        public void run() {

//                            if (shoppingLikeAapter != null) {
//                                shoppingLikeAapter.clear();
//                            }
//                            if (shoppingRecommendBrandAdapter != null) {
//                                shoppingRecommendBrandAdapter.clear();
//                            }

//                            if (shoppingStrategyAapter != null) {
//                                shoppingStrategyAapter.clear();
//                            }
                            scrollY = 0;
                            llShoppingSearch.setBackgroundColor(Color.argb(0x00, 0x09, 0xc0, 0xc7));
                            page = 1;
                            getShoppingData();
                            getShoppingLikeData();
                            getSpecialModelData();
                        }
                    }, 100);
                }
            });
        }
        getShoppingLikeData();
        getShoppingData();
        RxBus.getDefault().register(this);
        newPeopleCoupons();
        getSpecialModelData();
    }

    @Override
    protected void updateViews() {

    }

    //TODO 商城信息
    private void getShoppingData() {
        isEverRequest = false;

        ShoppingApi shoppingApi = new ShoppingApi(new HttpOnNextListener<ShoppingModel>() {
            @Override
            public void onNext(ShoppingModel model) {
                setShoppinpData(model);
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                e.printStackTrace();

            }
        }, (RxAppCompatActivity) (getContext()));
        shoppingApi.setSession(UserHelper.getInstance().getSession(getActivity()));
        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(shoppingApi);
    }

    //TODO 猜你喜欢数据
    private void getShoppingLikeData() {
        GuessYouLikeApi guessYouLikeApi = new GuessYouLikeApi(new HttpOnNextListener<GuessYouLikeModel>() {
            @Override
            public void onNext(GuessYouLikeModel model) {
                setShoppingLikeData(model.getList());
            }

            @Override
            public void onCacheNext(String cache) {
                super.onCacheNext(cache);

            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                PhoneUtils.ShowToastMessage(getActivity(), e.getMessage());
            }
        }, (RxAppCompatActivity) (getContext()), page + "");
        guessYouLikeApi.setSession(UserHelper.getInstance().getSession(getActivity()));
        guessYouLikeApi.setPage(page + "");
        guessYouLikeApi.setSize("10");
        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(guessYouLikeApi);

    }

    //TODO 猜你喜欢数据处理
    private void setShoppingLikeData(List<GuessYouLikeModel.ListBean> list) {
        if (shoppingLikeAapter != null&&page==1) {
            shoppingLikeAapter.clear();
        }
        if (list.size() < 9) {
            shoppingLikeAapter.stopMore();
        }

        if (list.size() == 0 && !PhoneUtils.isNetworkConnected(getActivity())) {
            shoppingLikeAapter.pauseMore();
            recycleViewLike.showError();
            return;
        }
        shoppingLikeAapter.addAll(list);
        shoppingLikeAapter.notifyDataSetChanged();

        if (shoppingLikeAapter.getAllData() == null || shoppingLikeAapter.getAllData().size() == 0) {
            llGuessLike.setVisibility(View.GONE);
        } else {
            llGuessLike.setVisibility(View.VISIBLE);
        }




    }

    //TODO 商城数据处理
    private void setShoppinpData(ShoppingModel model) {
        //车辆信息
        if (model == null || model.getOwnerCarList().size() == 0) {
            UserHelper.getInstance().setDefaultCarIndex(-1);
        } else {
            UserHelper.getInstance().setCarInfoList(model.getOwnerCarList());
        }
        showCarInfo();
        // banner
        bannersList = model.getBanners();
        mImageUrl.clear();
        if (model.getBanners() != null && model.getBanners().size() > 0) {
            for (int i = 0; i < model.getBanners().size(); i++) {
                mImageUrl.add(model.getBanners().get(i).getPicUrl() + "-320%7C1080");
            }
        } else {
            mImageUrl.add("");
        }
        icvShoppingBanner.setImageResources(mImageUrl, null, new ImageCycleView.ImageCycleViewListener() {
            @Override
            public void displayImage(String imageURL, ImageView imageView) {
                GlideUtils.loadImage(getActivity(), imageURL, imageView, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                    @Override
                    public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                    }

                    @Override
                    public void onLoadingError(String source, Exception e) {

                    }
                }, R.mipmap.default_banner, R.mipmap.default_banner);
            }

            @Override
            public void onImageClick(int position, View imageView) {
                bannerOnClick(bannersList, position);
            }
        });

        //袋鼠头条第一条数据
        tvDsHeadLine.setText(model.getHeadlines().getTitle());

        initSecKill(model.getGoodsActivity());
        initActivityZone(model.getActivityZoneList());
        initHotRecommend(model.getHotMallList());
        initBrandRecommnend(model.getGoodsBrandRecommendList());
        initStrategy(model.getStrategyList());
        initSpecial(model.getSpecialList());


//        新手大礼包是否显示5
        if (model.getSendNewPackageFlag().equals("true")) {
            ivNewbornZone.setVisibility(View.GONE);
        } else {
            ivNewbornZone.setVisibility(View.VISIBLE);
        }

//        2017-9-27无攻略隐藏标题
        if (model.getStrategyList() == null || model.getStrategyList().size() == 0) {
            llStrategy.setVisibility(View.GONE);
        } else {
            llStrategy.setVisibility(View.VISIBLE);
        }
    }


    //TODO 秒杀数据处理
    private void initSecKill(ShoppingModel.GoodsActivityBean model) {

        isEverRequest = true;
        if (model == null) {
            llSecKill.setVisibility(View.GONE);
            rvHomeSeckill.setVisibility(View.GONE);
            return;
        }
        long startTime = model.getStartTime();
        long stopTime = model.getStopTime();

        getServerTime(startTime, stopTime, true);


        List<ShoppingModel.GoodsActivityBean.ActivitySecondsKillBean> secKillModel = model.getActivitySecondsKill();

        if (TextUtils.isEmpty(model.getTitle())) {
            tvSecKill.setVisibility(View.INVISIBLE);
        } else {
            tvSecKill.setVisibility(View.VISIBLE);
            tvSecKill.setText(model.getTitle());
        }
        if (secKillModel != null && secKillModel.size() > 0) {
            llSecKill.setVisibility(View.VISIBLE);
            HomeSecKillAdapter adapter = new HomeSecKillAdapter(getActivity());
            GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 2);
            gridLayoutManager.setSpanSizeLookup(adapter.obtainGridSpanSizeLookUp(2));
            rvHomeSeckill.setVisibility(View.VISIBLE);
            rvHomeSeckill.setLayoutManager(gridLayoutManager);
            rvHomeSeckill.setAdapter(adapter);
            adapter.addAll(secKillModel);
            adapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener<ShoppingModel.GoodsActivityBean.ActivitySecondsKillBean>() {
                @Override
                public void onItemClick(View view, int position, ShoppingModel.GoodsActivityBean.ActivitySecondsKillBean model) {
                  /*  Intent ti = new Intent(getActivity(), GoodsDetailActivity.class);
                    ti.putExtra("fromType",SEC_KILL_TYPE);
                    ti.putExtra("specGroupKey", model.getSpecGroupKey());
                    ti.putExtra("price",model.getKillPrice());
                    startActivity(ti);*/
                    startActivity(new Intent(getActivity(), SecKillActivity.class).putExtra("fromType", PLATFORM_TYPE));
                }
            });
            llSecKill.setOnClickListener(onClick);

        } else {

            llSecKill.setVisibility(View.GONE);
        }


    }

    //TODO 秒杀倒计时服务器时间获取
    private void getServerTime(final long startTime, final long stopTime, final boolean isRefresh) {
        RequestParams params = new RequestParams(Constants.APP_API_BASE + Constants.PUB_SERVER_TIME);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                String exp = JsonUtil.getJsonValuesString(result, "exp");
                boolean flag = JsonUtil.getJsonValuesBoolean(result, "flag");
                MyLog.e("asus", result);
                if (flag) {
                    long currentTime = JsonUtil.getJsonValuesLong(result, "serverTime");
                    if (isRefresh) {
                        if (startTime > currentTime) {
                            isStart = true;
                            endTime = startTime;
                        } else {
                            isStart = false;
                            endTime = stopTime;
                        }
                    }

                    initCoutDown(cvSeckill, currentTime);
                } else {
                    PhoneUtils.ShowToastMessage(getActivity(), exp);
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                PhoneUtils.ShowToastMessage(getActivity(), ex.getMessage());
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });

    }

    //TODO 秒杀倒计时
    private void initCoutDown(CountdownView cvSeckill, long serverTime) {
        if (cvSeckill != null) {
            cvSeckill.stop();
            Long startTime = serverTime;
            if (isStart) {
                tvSecSign.setText("距开始");
            } else {
                tvSecSign.setText("距结束");
            }
            if (endTime == 0) {
                Date date = new Date(serverTime);//取时间
                Calendar calendar = new GregorianCalendar();
                calendar.setTime(date);
                calendar.add(Calendar.DATE, 1);//把日期往后增加一天.整数往后推,负数往前移动
                date = calendar.getTime(); //这个时间就是日期往后推一天的结果
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                String dateString = formatter.format(date) + " 00:00:00";
                endTime = dateToMs(dateString);
                cvSeckill.start((endTime - startTime) > 0 ? (endTime - startTime) : 0);
            } else {
                cvSeckill.start((endTime - startTime) > 0 ? (endTime - startTime) : 0);
            }

        }
    }

    // TODO 活动专区
    private void initActivityZone(final List<ShoppingModel.ActivityZoneListBean> activityZoneList) {
        if (activityZoneList != null && activityZoneList.size() > 0) {
            GlideUtils.loadImage(mContext, activityZoneList.get(0).getShowToHomeLogo(), ivFerrisWheel, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {
                            ivFerrisWheel.setImageDrawable(resource.getCurrent());
                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            }, R.mipmap.default_icon, R.mipmap.default_icon);
        }
        tvFerrisWheel.setText(activityZoneList.get(0).getTitle());
        ivFerrisWheel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (activityZoneList != null && activityZoneList.size() > 0) {
                    Intent intent = new Intent();
                    ShoppingModel.ActivityZoneListBean o = activityZoneList.get(0);
                    if ("strategy".equals(o.getLinkType())) {
                        intent.setClass(getActivity(), InformationDetailActivity.class);
                        intent.putExtra("title", o.getTitle());
                        intent.putExtra("content", o.getDescription1());
                        intent.putExtra("imgUrl", o.getLogo());
                        intent.putExtra("infoId", o.getLinkTypeId());
                        intent.putExtra("isCollect", o.isCollect());
                        intent.putExtra("collectType", "strategy");
                        startActivity(intent);

                    } else if ("preferential".equals(o.getLinkType())) {
                        WebViewRequestParam webViewRequestParam = new WebViewRequestParam(o.getLinkTypeId() + "");
                        webViewRequestParam.setRequestMethod(REQUEST_POST);
                        intent.setClass(getActivity(), WebViewActivity.class);
                        intent.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam);
                        intent.putExtra("type", "preferential");
                        intent.putExtra("mFromTypeId",o.getGoodsActivityId()+"");
                        startActivity(intent);
                    } else if ("url".equals(o.getLinkType())) {
                        WebViewRequestParam webViewRequestParam = new WebViewRequestParam(o.getUrl());
                        if (!TextUtils.isEmpty(o.getUrl())) {
                            if (o.getUrl().contains("own/shop/priceRatio")) {
                                webViewRequestParam.setRequestMethod(REQUEST_GET);
                                intent.setClass(getActivity(), WebViewActivity.class);
                                intent.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam);
                                intent.putExtra("type", "袋鼠管家");
                                intent.putExtra("mFromTypeId",o.getGoodsActivityId()+"");
                                startActivity(intent);
                            } else if (o.getUrl().contains("own/shop/preferential")) {
                                webViewRequestParam.setRequestMethod(REQUEST_POST);
                                intent.setClass(getActivity(), WebViewActivity.class);
                                intent.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam);
                                intent.putExtra("type", "preferential");
                                intent.putExtra("mFromTypeId",o.getGoodsActivityId()+"");
                                startActivity(intent);
                            } else if (o.getUrl().contains("own/shop/luckDraw")) {
                                WebViewRequestParam webViewRequestParam2 = new WebViewRequestParam(Constants.APP_API_BASE + Constants.OWN_SHOP_LUCKDRAW);
                                webViewRequestParam2.setRequestMethod(REQUEST_POST);
                                webViewRequestParam2.setParams("session=" + UserHelper.getInstance().getSession(getActivity()));
                                webViewRequestParam2.setTitle("转盘抽奖");
                                Intent intent2 = new Intent(getActivity(), LuckDrawWebviewActivity.class);
                                intent2.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam2);
                                getActivity().startActivity(intent2);

                            } else if (o.getUrl().contains("/own/shop/doubleEleven")) {
                                WebViewRequestParam webViewRequestParam2 = new WebViewRequestParam(o.getUrl());
                                webViewRequestParam2.setRequestMethod(REQUEST_POST);
                                Intent intent2 = new Intent(getActivity(), WebViewActivity.class);
                                intent2.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam2);
                                intent2.putExtra("type", "doubleEleven");
                                intent2.putExtra("mFromTypeId",o.getGoodsActivityId()+"");
                                startActivity(intent2);
                            } else {
                                intent.setClass(getActivity(), HotShopWebActivity.class);
                                intent.putExtra("title", o.getTitle());
                                intent.putExtra("url", o.getUrl());
                                startActivity(intent);
                            }


                        } else {
                            intent.setClass(getActivity(), HotShopWebActivity.class);
                            intent.putExtra("title", o.getTitle());
                            intent.putExtra("url", o.getUrl());
                            startActivity(intent);
                        }


                    }
                }

            }
        });

        if (activityZoneList != null && activityZoneList.size() > 1) {
            GlideUtils.loadImage(mContext, activityZoneList.get(1).getShowToHomeLogo(), ivPriceRatio, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {
                    ivPriceRatio.setImageDrawable(resource.getCurrent());
                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            }, R.mipmap.default_icon, R.mipmap.default_icon);

        }
        tvPriceRatio.setText(activityZoneList.get(1).getTitle());
        tvPriceRatioSub.setText(activityZoneList.get(1).getShowToHomeTitle1());
        ivPriceRatio.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (activityZoneList != null && activityZoneList.size() > 1) {
                    Intent intent = new Intent();
                    ShoppingModel.ActivityZoneListBean o = activityZoneList.get(1);
                    if ("strategy".equals(o.getLinkType())) {
                        intent.setClass(getActivity(), InformationDetailActivity.class);
                        intent.putExtra("title", o.getTitle());
                        intent.putExtra("content", o.getDescription1());
                        intent.putExtra("imgUrl", o.getLogo());
                        intent.putExtra("infoId", o.getLinkTypeId());
                        intent.putExtra("isCollect", o.isCollect());
                        intent.putExtra("collectType", "strategy");
                        startActivity(intent);

                    } else if ("preferential".equals(o.getLinkType())) {
                        WebViewRequestParam webViewRequestParam = new WebViewRequestParam(o.getLinkTypeId() + "");
                        webViewRequestParam.setRequestMethod(REQUEST_POST);
                        intent.setClass(getActivity(), WebViewActivity.class);
                        intent.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam);
                        intent.putExtra("type", "preferential");
                        intent.putExtra("mFromTypeId",o.getGoodsActivityId()+"");
                        startActivity(intent);
                    } else if ("url".equals(o.getLinkType())) {
                        WebViewRequestParam webViewRequestParam = new WebViewRequestParam(o.getUrl());
                        if (!TextUtils.isEmpty(o.getUrl())) {
                            if (o.getUrl().contains("own/shop/priceRatio")) {
                                webViewRequestParam.setRequestMethod(REQUEST_GET);
                                intent.setClass(getActivity(), WebViewActivity.class);
                                intent.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam);
                                intent.putExtra("type", "袋鼠管家");
                                intent.putExtra("mFromTypeId",o.getGoodsActivityId()+"");
                                startActivity(intent);
                            } else if (o.getUrl().contains("own/shop/preferential")) {
                                webViewRequestParam.setRequestMethod(REQUEST_POST);
                                intent.setClass(getActivity(), WebViewActivity.class);
                                intent.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam);
                                intent.putExtra("type", "preferential");
                                intent.putExtra("mFromTypeId",o.getGoodsActivityId()+"");
                                startActivity(intent);
                            } else if (o.getUrl().contains("own/shop/luckDraw")) {
                                WebViewRequestParam webViewRequestParam2 = new WebViewRequestParam(Constants.APP_API_BASE + Constants.OWN_SHOP_LUCKDRAW);
                                webViewRequestParam2.setRequestMethod(REQUEST_POST);
                                webViewRequestParam2.setParams("session=" + UserHelper.getInstance().getSession(getActivity()));
                                webViewRequestParam2.setTitle("转盘抽奖");
                                Intent intent2 = new Intent(getActivity(), LuckDrawWebviewActivity.class);
                                intent2.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam2);
                                getActivity().startActivity(intent2);

                            } else if (o.getUrl().contains("/own/shop/doubleEleven")) {
                                WebViewRequestParam webViewRequestParam2 = new WebViewRequestParam(o.getUrl());
                                webViewRequestParam2.setRequestMethod(REQUEST_POST);
                                Intent intent2 = new Intent(getActivity(), WebViewActivity.class);
                                intent2.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam2);
                                intent2.putExtra("type", "doubleEleven");
                                intent2.putExtra("mFromTypeId",o.getGoodsActivityId()+"");
                                MyLog.e("yang","o.getGoodsActivityId()=="+o.getGoodsActivityId()+"");
                                startActivity(intent2);
                            } else if(o.getUrl().contains("/own/shop/sunburn")){
                                WebViewRequestParam webViewRequestParam3 = new WebViewRequestParam(Constants.APP_API_BASE + Constants.OWN_SHOP_SUNBURN);
                                webViewRequestParam3.setRequestMethod(REQUEST_GET);
                                webViewRequestParam3.setTitle("晒评价,领现金券");
                                Intent intent3 = new Intent(getActivity(), NewWebViewActivity.class);
                                intent3.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam3);
                                startActivity(intent3);
                            }else {
                                intent.setClass(getActivity(), HotShopWebActivity.class);
                                intent.putExtra("title", o.getTitle());
                                intent.putExtra("url", o.getUrl());
                                startActivity(intent);
                            }


                        } else {
                            intent.setClass(getActivity(), HotShopWebActivity.class);
                            intent.putExtra("title", o.getTitle());
                            intent.putExtra("url", o.getUrl());
                            startActivity(intent);
                        }


                    }
                }

            }
        });
    }

    //TODO 热门推荐数据处理
    private void initHotRecommend(List<ShoppingModel.HotMallListBean> categoryList) {
        ArrayList<ShoppingModel.HotMallListBean> homeHotShopTopList = new ArrayList<>();
        ArrayList<ShoppingModel.HotMallListBean> homeHotShopBottomList = new ArrayList<>();
        for (int i = 0; i < categoryList.size(); i++) {
            if (i <= 1) {
                homeHotShopTopList.add(categoryList.get(i));
            } else if (i <= 5) {
                homeHotShopBottomList.add(categoryList.get(i));
            }


        }

        rvHomeHotTop.setLayoutManager(new GridLayoutManager(getActivity(), 2));
        HomeHotShopTopAdapter hotShopTopAdapter = new HomeHotShopTopAdapter(getActivity());

        rvHomeHotTop.setAdapter(hotShopTopAdapter);
        hotShopTopAdapter.addAll(homeHotShopTopList);

        rvHomeHotBottom.setLayoutManager(new GridLayoutManager(getActivity(), 4));
        HomeHotShopBottomAdapter hotShopBottomAdapter = new HomeHotShopBottomAdapter(getActivity());

        rvHomeHotBottom.setAdapter(hotShopBottomAdapter);
        hotShopBottomAdapter.addAll(homeHotShopBottomList);

        hotShopTopAdapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener<ShoppingModel.HotMallListBean>() {
            @Override
            public void onItemClick(View view, int position, ShoppingModel.HotMallListBean o) {
                if ("category".equals(o.getLinkType())) {
                    Intent intent = new Intent(getActivity(), GoodsListActivity.class);
                    intent.putExtra("fromType", CLASSIFY_TYPE);
                    intent.putExtra("categoryId", o.getCategoryId());
                    intent.putExtra("goodsType", PLATFORM_TYPE);
                    intent.putExtra("title", o.getTitle());
                    intent.putExtra("mFromType",Constants.GOODSSOURCE_STORE);
                    intent.putExtra("mFromTypeId", "0");
                    startActivity(intent);
                } else if ("url".equals(o.getLinkType())) {
                    Intent intent = new Intent(getActivity(), HotShopWebActivity.class);
                    intent.putExtra("title", o.getTitle());
                    intent.putExtra("url", o.getUrl());
                    startActivity(intent);
                }

            }
        });
        hotShopBottomAdapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener<ShoppingModel.HotMallListBean>() {
            @Override
            public void onItemClick(View view, int position, ShoppingModel.HotMallListBean o) {
                if ("category".equals(o.getLinkType())) {
                    Intent intent = new Intent(getActivity(), GoodsListActivity.class);
                    intent.putExtra("fromType", CLASSIFY_TYPE);
                    intent.putExtra("categoryId", o.getCategoryId());
                    intent.putExtra("goodsType", PLATFORM_TYPE);
                    intent.putExtra("title", o.getTitle());
                    intent.putExtra("mFromType",Constants.GOODSSOURCE_STORE);
                    intent.putExtra("mFromTypeId", "0");
                    startActivity(intent);
                } else if ("url".equals(o.getLinkType())) {
                    Intent intent = new Intent(getActivity(), HotShopWebActivity.class);
                    intent.putExtra("title", o.getTitle());
                    intent.putExtra("url", o.getUrl());
                    startActivity(intent);
                }
            }
        });

    }

    //TODO 明星品牌数据处理
    private void initBrandRecommnend(List<ShoppingModel.GoodsBrandRecommendListBean> goodsBrandRecommendList) {



        if (goodsBrandRecommendList == null || goodsBrandRecommendList.size() < 9) {
            llRecommendBrand.setVisibility(View.GONE);
            return;
        } else {

            llRecommendBrand.setVisibility(View.VISIBLE);
        }

        if (shoppingRecommendBrandAdapter != null) {
            shoppingRecommendBrandAdapter.clear();
        }else {
            rvRecommendBrand.setAdapter(shoppingRecommendBrandAdapter = new ShoppingRecommendBrandAdapter(getActivity()));
        }
        if (goodsBrandRecommendList.size() > 9) {
            List<ShoppingModel.GoodsBrandRecommendListBean> recommendListBeans = new ArrayList<>();
            for (int i = 0; i < 9; i++) {
                recommendListBeans.add(goodsBrandRecommendList.get(i));
            }

            shoppingRecommendBrandAdapter.addAll(recommendListBeans);
        } else {
            shoppingRecommendBrandAdapter.addAll(goodsBrandRecommendList);
        }
        shoppingRecommendBrandAdapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener<ShoppingModel.GoodsBrandRecommendListBean>() {
            @Override
            public void onItemClick(View view, int position, ShoppingModel.GoodsBrandRecommendListBean goodsBrandRecommendListBean) {
                Intent intent = new Intent(getActivity(), GoodsListActivity.class);
                intent.putExtra("fromType", CLASSIFY_TYPE);
                intent.putExtra("goodsBrandId", goodsBrandRecommendListBean.getGoodsBrandId());
                intent.putExtra("goodsType", PLATFORM_TYPE);
                intent.putExtra("title", goodsBrandRecommendListBean.getChName());
                intent.putExtra("mFromType",Constants.GOODSSOURCE_BRAND);
                intent.putExtra("mFromTypeId",goodsBrandRecommendListBean.getGoodsBrandId()+"");
                MyLog.e("yang","****=="+goodsBrandRecommendListBean.getGoodsBrandId());
                startActivity(intent);
            }


        });


    }

    //TODO 模板数据处理
    private void initSpecial(List<ShoppingModel.SpecialListBean> specialList) {
        if (specialList == null || specialList.size() == 0) {
            rvShoppingSpecial.setVisibility(View.GONE);
            return;
        } else {
            rvShoppingSpecial.setVisibility(View.VISIBLE);
        }
        ShoppingSpecialAdapter shoppingSpecialAdapter = new ShoppingSpecialAdapter(getActivity());
        rvShoppingSpecial.setLayoutManager(new LinearLayoutManager(getActivity()));
        shoppingSpecialAdapter.addAll(specialList);
        rvShoppingSpecial.setAdapter(shoppingSpecialAdapter);

    }

    //TODO 专题攻略数据处理
    private void initStrategy(List<ShoppingModel.StrategyListBean> strategyList) {
        if (strategyList == null || strategyList.size() == 0) {
            llStrategy.setVisibility(View.GONE);
            return;
        } else {
            llStrategy.setVisibility(View.VISIBLE);
        }

        if (shoppingStrategyAapter != null) {
            shoppingStrategyAapter.clear();
        }else {
            recycleviewStrategy.setAdapter(shoppingStrategyAapter = new ShoppingStrategyAdapter(getActivity()));
        }
        shoppingStrategyAapter.addAll(strategyList);
        shoppingStrategyAapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener<ShoppingModel.StrategyListBean>() {
            @Override
            public void onItemClick(View view, int position, ShoppingModel.StrategyListBean model) {
                Intent ti = new Intent(getActivity(), InformationDetailActivity.class);
                ti.putExtra("title", model.getTitle());
                ti.putExtra("content", model.getContent());
                ti.putExtra("imgUrl", model.getCoverUrl());
                ti.putExtra("infoId", model.getInfoId());
                ti.putExtra("isCollect", model.isCollect());
                ti.putExtra("collectType", "strategy");
                ti.putExtra("position", position);
                ti.putExtra("mType", "listStrategy");
                startActivity(ti);

            }


        });
    }


    //TODO 点击事件处理
    View.OnClickListener onClick = new View.OnClickListener() {
        public void onClick(View v) {
            switch (v.getId()) {
                //车辆相关
                case R.id.ll_add_car:
                    if (checkLoginState()) {
                        if (UserHelper.getInstance().getDefaultCarIndex() == 0 && UserHelper.getInstance().getDefaultCar() == null) {
                            PhoneUtils.ShowToastMessage(mContext, "数据加载中,请稍候!");
                        } else if (UserHelper.getInstance().getDefaultCarIndex() == -1) {
                            Intent intent = new Intent();
                            intent.setClass(getActivity(), PickBrandActivity.class);
                            intent.putExtra(PickBrandActivity.START_FLAG, 0);
                            startActivityForResult(intent, REQUEST_CODE_ADD_CAR);
                        } else if (UserHelper.getInstance().getDefaultCar() != null) {
                            startActivity(new Intent(getActivity(), CarDossierActivity.class));
                        }
                    }
                    break;
                //车品商城
                case R.id.ll_home_reach:
                    Intent ti = new Intent(getActivity(), HotShopClassifyActivity2.class);
//                    ti.putExtra("title", "车品商城");
                    startActivity(ti);
                    break;
                //违章查询
                case R.id.ll_home_vehicle:
                    if (checkLoginState()) {
                        Intent ti2 = new Intent(getActivity(), SelectIllegalQueryActivity.class);
                        startActivity(ti2);
                    }
                    break;
                // 领券中心
                case R.id.ll_home_coupons:
                    Intent ti3 = new Intent(getActivity(), GetCouponsCenterActivity.class);
                    ti3.putExtra("isPlatform", true);
                    startActivity(ti3);
                    break;
                //保养检测
                case R.id.ll_home_maintain:
                    if (checkLoginState()) {
                        if (UserHelper.getInstance().getDefaultCarIndex() == 0 && UserHelper.getInstance().getDefaultCar() == null) {
                            Toast.makeText(mContext, "数据加载中,请稍候!", Toast.LENGTH_SHORT).show();
                        } else if (UserHelper.getInstance().getDefaultCarIndex() == -1) {
                            Intent intent = new Intent();
                            intent.setClass(getActivity(), PickBrandActivity.class);
                            intent.putExtra(PickBrandActivity.START_FLAG, 0);
                            startActivityForResult(intent, REQUEST_CODE_ADD_CAR);
                        } else if (UserHelper.getInstance().getDefaultCar() != null) {
                            startActivity(new Intent(getActivity(), MaintenanceDetectionActivity.class).putExtra(Constants.TRANSMISSION_CONTENT_KEY, UserHelper.getInstance().getDefaultCar()));
                        }
                    }
                    break;
                //FM908
                case R.id.ll_908:
                    WebViewRequestParam webViewRequestParam = new WebViewRequestParam(Constants.APP_API_BASE + Constants.OWN_SHOP_CLUB);
                    webViewRequestParam.setRequestMethod(REQUEST_GET);
                    webViewRequestParam.setTitle("FM908");
                    Intent intent1 = new Intent(getActivity(), NewWebViewActivity.class);
                    intent1.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam);
                    startActivity(intent1);
                    break;
                case R.id.ll_anhui:
                    WebViewRequestParam webViewRequestParam4 = new WebViewRequestParam(Constants.APP_API_BASE + Constants.OWN_SHOP_BUSINESSDAILY);
                    webViewRequestParam4.setRequestMethod(REQUEST_GET);
                    webViewRequestParam4.setTitle("安徽商报");
                    Intent intent4 = new Intent(getActivity(), NewWebViewActivity.class);
                    intent4.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam4);
                    startActivity(intent4);
                    break;
                //新人大礼包
                case R.id.iv_newborn_zone:
                    WebViewRequestParam webViewRequestParam2 = new WebViewRequestParam(Constants.APP_API_BASE + Constants.OWN_SHOP_NEWGIFBG + "?session=" + UserHelper.getInstance().getSession(getActivity()));
                    webViewRequestParam2.setRequestMethod(REQUEST_GET);
                    webViewRequestParam2.setTitle("新人大礼包");
                    Intent intent2 = new Intent(getActivity(), NewWebViewActivity.class);
                    intent2.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam2);
                    startActivity(intent2);
                    break;
                //秒杀
                case R.id.ll_sec_kill:
                    startActivity(new Intent(getActivity(), SecKillActivity.class).putExtra("fromType", PLATFORM_TYPE));
                    break;
                //袋鼠头条
                case R.id.ll_ds_head_line:
                    if (showFlagHeadLines) {
                        startActivity(new Intent(getActivity(), HeadLineActivity.class));
                    }
                    break;

                //心得
                case R.id.iv_shopping_experience:
                    WebViewRequestParam webViewRequestParam3 = new WebViewRequestParam(Constants.APP_API_BASE + Constants.OWN_SHOP_SUNBURN);
                    webViewRequestParam3.setRequestMethod(REQUEST_GET);
                    webViewRequestParam3.setTitle("晒评价,领现金券");
                    Intent intent3 = new Intent(getActivity(), NewWebViewActivity.class);
                    intent3.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam3);
                    startActivity(intent3);
                    break;
                //签到
                case R.id.iv_sign_in:
                    if (checkLoginState()) {
                        WebViewRequestParam webViewRequestParamSign = new WebViewRequestParam(Constants.APP_API_BASE + Constants.OWN_SHOP_SIGNED);
                        webViewRequestParamSign.setRequestMethod(REQUEST_POST);
                        webViewRequestParamSign.setParams("session=" + UserHelper.getInstance().getSession(getActivity()));
                        webViewRequestParamSign.setTitle("签到有礼");
                        Intent intentSign = new Intent(getActivity(), NewWebViewActivity.class);
                        intentSign.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParamSign);
                        startActivity(intentSign);
                    }
                    break;

                //热门推荐更多
                case R.id.tv_hot_recommend_more:
                    MyLog.e("yang","热门推荐更多");
                    Intent intent = new Intent(getActivity(), HotShopClassifyActivity2.class);
                    intent.putExtra("goodsType", PLATFORM_TYPE);
                    startActivity(intent);
                    break;

            }
        }
    };


    @Override
    public void onLoadMore() {
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                //加载更多
                if (!PhoneUtils.isNetworkConnected(getActivity())) {
                    shoppingLikeAapter.pauseMore();
                    recycleViewLike.showError();
                    return;
                }
                page++;
                getShoppingLikeData();

            }
        }, 100);
    }

    //TODO 时间转换
    public static long dateToMs(String dateTime) {
        final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date dm = null;
        try {
            dm = sdf.parse(dateTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if (dm == null) {
            return 0l;
        }
        return dm.getTime();
    }

    @Override
    public void onResume() {
        super.onResume();
        if (isEverRequest) {
            getServerTime(0, 0, false);
        }
        if (needRefreshCar) {
            showCarInfo();
        }

    }

    @Override
    public void onPause() {
        super.onPause();
        needRefreshCar = true;
    }


    //wangyang添加
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_ADD_CAR && resultCode == Constants.ACTIVITY_RESULT_CODE_CAR_ADD) {
            // TODO 车辆添加成功返回
            needRefreshCar = false;
            getMyGarage();
        }
    }

    private void showCarInfo() {
        CarInfo mCarInfo = UserHelper.getInstance().getDefaultCar();
        if (ivAddCar != null && tvAddCarTips != null) {
            if (mCarInfo == null) {
                ivAddCar.setImageResource(R.mipmap.icon_my_car);
                tvAddCar.setText("添加我的爱车");
                tvAddCarTips.setText("袋鼠按车型推荐合适商品");

            } else {
                if (TextUtils.isEmpty(mCarInfo.getImageSrc())) {
                    ivAddCar.setImageResource(R.mipmap.icon_my_car);
                } else {
                    GlideUtils.loadImage(mContext, mCarInfo.getImageSrc(), ivAddCar, null, R.mipmap.icon_my_car, R.mipmap.icon_my_car);
                }
                tvAddCar.setText(mCarInfo.getLicenseNumber());
                tvAddCarTips.setText(mCarInfo.getChName() + "  " + (mCarInfo.getCurrentMileage() > 0 ? (mCarInfo.getCurrentMileage() + "km") : ""));
            }
        }

    }

    private void getMyGarage() {
        RequestParams params = new RequestParams(Constants.APP_API_BASE + Constants.OWN_CARS);
        params.addBodyParameter("session", UserHelper.getInstance().getSession(mContext));
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                String data = PhoneUtils.checkResponseFlag(getActivity(), result);
                if (data != null) {
                    List<CarInfo> dataList = new ArrayList<>();
                    try {
                        Gson gson = new GsonBuilder().create();
                        dataList = gson.fromJson(data, new TypeToken<List<CarInfo>>() {
                        }.getType());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    UserHelper.getInstance().setCarInfoList(dataList);
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {
                showCarInfo();
            }
        });
    }

    private void bannerOnClick(List<ShoppingModel.BannersBean> list, int position) {
        ShoppingModel.BannersBean model = list.get(position);
        MyLog.e("yang", "model.getContactId()==" + model.getContactId());
        if (list.get(position).getEnableStatus().equals("true")) {
            if (model.getContactType().equals("strategy")) {
                Intent ti = new Intent(getActivity(), InformationDetailActivity.class);
                ti.putExtra("title", model.getTitle());
                ti.putExtra("content", model.getDescription());
                ti.putExtra("imgUrl", model.getPicUrl());
                ti.putExtra("isCollect", model.isCollect());
                ti.putExtra("infoId", Integer.valueOf(model.getContactId()));
                ti.putExtra("collectType", "strategy");
                ti.putExtra("position", position);
                ti.putExtra("mType", "bannerStrategy");
                startActivity(ti);
            } else if (model.getContactType().equals("url")) {
                if (!TextUtils.isEmpty(model.getContactId())) {
                    if (model.getContactId().contains("own/shop/luckDraw")) {
                        WebViewRequestParam webViewRequestParam = new WebViewRequestParam(Constants.APP_API_BASE + Constants.OWN_SHOP_LUCKDRAW);
                        webViewRequestParam.setRequestMethod(REQUEST_POST);
                        webViewRequestParam.setParams("session=" + UserHelper.getInstance().getSession(getActivity()));
                        webViewRequestParam.setTitle("转盘抽奖");
                        Intent intent = new Intent(getActivity(), LuckDrawWebviewActivity.class);
                        intent.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam);
                        startActivity(intent);
                    } else if (model.getContactId().contains("/own/shop/doubleEleven")) {
                        WebViewRequestParam webViewRequestParam = new WebViewRequestParam(model.getContactId());
                        webViewRequestParam.setRequestMethod(REQUEST_POST);
                        Intent intent = new Intent(getActivity(), WebViewActivity.class);
                        intent.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam);
                        intent.putExtra("type", "doubleEleven");
                        intent.putExtra("mFromTypeId",model.getContactId()+"");
                        startActivity(intent);
                    } else if (model.getContactId().contains("own/shop/businessDaily")) {
                        WebViewRequestParam webViewRequestParam4 = new WebViewRequestParam(Constants.APP_API_BASE + Constants.OWN_SHOP_BUSINESSDAILY);
                        webViewRequestParam4.setRequestMethod(REQUEST_GET);
                        webViewRequestParam4.setTitle("安徽商报");
                        Intent intent4 = new Intent(getActivity(), NewWebViewActivity.class);
                        intent4.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam4);
                        startActivity(intent4);
                    } else if (model.getContactId().contains("own/shop/club")) {
                        WebViewRequestParam webViewRequestParam = new WebViewRequestParam(Constants.APP_API_BASE + Constants.OWN_SHOP_CLUB);
                        webViewRequestParam.setRequestMethod(REQUEST_GET);
                        webViewRequestParam.setTitle("FM908");
                        Intent intent1 = new Intent(getActivity(), NewWebViewActivity.class);
                        intent1.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam);
                        startActivity(intent1);
                    } else if (model.getContactId().contains("own/shop/newGiftBag")) {
                        WebViewRequestParam webViewRequestParam2 = new WebViewRequestParam(Constants.APP_API_BASE + Constants.OWN_SHOP_NEWGIFBG + "?session=" + UserHelper.getInstance().getSession(getActivity()));
                        webViewRequestParam2.setRequestMethod(REQUEST_GET);
                        webViewRequestParam2.setTitle("新人大礼包");
                        Intent intent2 = new Intent(getActivity(), NewWebViewActivity.class);
                        intent2.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam2);
                        startActivity(intent2);
                    } else if (model.getContactId().contains("own/shop/sunburn")) {
                        WebViewRequestParam webViewRequestParam3 = new WebViewRequestParam(Constants.APP_API_BASE + Constants.OWN_SHOP_SUNBURN);
                        webViewRequestParam3.setRequestMethod(REQUEST_GET);
                        webViewRequestParam3.setTitle("晒评价,领现金券");
                        Intent intent3 = new Intent(getActivity(), NewWebViewActivity.class);
                        intent3.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam3);
                        startActivity(intent3);
                    } else {
                        WebViewRequestParam webViewRequestParam = new WebViewRequestParam(model.getContactId());
                        webViewRequestParam.setRequestMethod(REQUEST_GET);
                        Intent intent = new Intent(getActivity(), WebViewActivity.class);
                        intent.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam);
                        intent.putExtra("mFromTypeId",model.getContactId()+"");
                        intent.putExtra("type", "袋鼠管家");
                        startActivity(intent);
                    }


                }


            } else if (model.getContactType().equals("preferential")) {
                if (!TextUtils.isEmpty(model.getContactId())) {
                    WebViewRequestParam webViewRequestParam = new WebViewRequestParam(model.getContactId());
                    webViewRequestParam.setRequestMethod(REQUEST_POST);
                    Intent intent = new Intent(getActivity(), WebViewActivity.class);
                    intent.putExtra(Constants.TRANSMISSION_CONTENT_KEY, webViewRequestParam);
                    intent.putExtra("type", "preferential");
                    intent.putExtra("mFromTypeId",model.getContactId()+"");
                    startActivity(intent);
                }
            } else if (model.getContactType().equals("goods")) { //商品详情
                Intent intent = new Intent(getActivity(), GoodsDetailActivity.class);
                intent.putExtra("goodsId", Integer.parseInt(model.getContactId()));
                intent.putExtra("mFromType",Constants.GOODSSOURCE_STORE);
                intent.putExtra("mFromTypeId", model.getContactId()+"");
                startActivity(intent);
            } else if (model.getContactType().equals("category")) { //商品分类
                MyLog.e("yang", "id====" + model.getContactId());
                Intent intent = new Intent(getActivity(), GoodsListActivity.class);
                intent.putExtra("fromType", 0);
                intent.putExtra("categoryId", Integer.parseInt(model.getContactId()));
                intent.putExtra("goodsType", 0);
                intent.putExtra("title", model.getCategoryName());
                intent.putExtra("mFromType", Constants.GOODSSOURCE_STORE);
                intent.putExtra("mFromTypeId", "0");
                startActivity(intent);
            }

        }
    }

    @Subscribe(code = Constants.REFRESH_SHOPPING_GIFT, threadMode = ThreadMode.MAIN)
    public void refreshGift(final CommonEvent event) {
        ivNewbornZone.setVisibility(View.GONE);
    }

    @OnClick(R.id.ll_shopping_search)
    public void onViewClicked() {
        Intent intent = new Intent(getActivity(), GoodsSearchHistoryActivity.class);
        intent.putExtra("goodsType", PLATFORM_TYPE);
        startActivity(intent);
    }

    @Subscribe(code = Constants.REFRESH_SHOPPING, threadMode = ThreadMode.MAIN)
    public void refreshShopping(CommonEvent event) {
        MyLog.e("yang", "商城刷新");
        getShoppingData();
        MainActivity.refreshShopping = false;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        RxBus.getDefault().unRegister(this);
    }

    //领取优惠券
    private void newPeopleCoupons() {
        if (UserHelper.getInstance().getSessionInfoModel(getActivity()) != null && UserHelper.getInstance().getSessionInfoModel(getActivity()).getMoney() != 0 && UserHelper.getInstance().isLogined()) {
            SessionInfoModel sessionInfoModel = UserHelper.getInstance().getSessionInfoModel(getActivity());
            final GuideHelper guideHelper = new GuideHelper(getActivity());
            //add custom view
            View view = guideHelper.inflate(R.layout.custom_wallet_view);
            TextView tvDiscountMoney = (TextView) view.findViewById(R.id.tv_discount_money);
            view.findViewById(R.id.img_wallet_cancel).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    guideHelper.dismiss();
                }
            });
            view.findViewById(R.id.img_look).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivity(new Intent(getActivity(), CouponsActivity.class));
                    guideHelper.dismiss();
                }
            });
            tvDiscountMoney.setText(String.format("%.2f", UserHelper.getInstance().getSessionInfoModel(getActivity()).getMoney()));
            GuideHelper.TipData tipDataCustom = new GuideHelper.TipData(view, Gravity.CENTER);
            guideHelper.addPage(false, tipDataCustom);
            guideHelper.show(false);
            sessionInfoModel.setMoney(0);
            UserHelper.getInstance().setSessionInfoModel(getActivity(), sessionInfoModel);
        } else {
            MyLog.e("yang", "新人领取优惠券");
        }

    }

    private void getSpecialModelData() {
        RequestParams params = new RequestParams(Constants.APP_API_BASE + Constants.OWN_SPECIAL_MODEL);
        if (UserHelper.getInstance().getSessionInfoModel(mContext) != null &&
                UserHelper.getInstance().getSessionInfoModel(mContext).getSession() != null) {
            params.addBodyParameter("session", "" + UserHelper.getInstance().getSessionInfoModel(mContext).getSession());
        }
        MyLog.d("RAVEN", "params = " + params);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                String data = PhoneUtils.checkResponseFlag(getActivity(), result);
                if (data != null) {
                    MyLog.d("RAVEN", "data = " + data);
                    List<SpecialModel> specialModelList = GsonUtils.fromJsonList(data, SpecialModel.class);
                    if (specialModelList != null && specialModelList.size() > 0) {
                        specialAreaAdapter.clear();
                        specialAreaAdapter.addAll(specialModelList);
                    }
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {
            }
        });
    }
}
